//
//  secondViewController.m
//  Test-ZhuangHaiPeng
//
//  Created by Hai Peng Zhuang on 12/16/15.
//  Copyright © 2015 itcast. All rights reserved.
//

#import "secondViewController.h"

@interface secondViewController ()<UIScrollViewDelegate>
@property(nonatomic,weak) UIPageControl  *pageControl;
#define newFeatureImageCount 3
@end

@implementation secondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    if (self.title ) {
        self.navigationItem.title = @"答案";
        self.view.backgroundColor  = [UIColor whiteColor];
        // Do any additional setup after loading the view.
        UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, 300, 80)];
        title.numberOfLines = 0;
        title.text = self.title;
        [self.view addSubview:title];
        UILabel *contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 200, 300, 400)];
        contentLabel.text = self.content;
        contentLabel.numberOfLines = 0;
        [self.view addSubview:contentLabel];
    }else
    {
        
        /*  添加scrollview  */
        [self setUpScroll];
        
        //    /* 添加pageControll */
        [self setUpPageControl];
        
    }
    

    

    
}

- (void)setUpScroll
{
    UIScrollView *scrollview = [[UIScrollView alloc]init];
    scrollview.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    scrollview.delegate = self;
    [self.view addSubview:scrollview];
    
    // 设置图片的宽高
    CGFloat imageW = scrollview.frame.size.width;
    CGFloat imageH = scrollview.frame.size.height;
    
    for (int i = 0; i < newFeatureImageCount; i++ )
    {
        UIImageView *imageView = [[UIImageView alloc]init];
        
        NSString *imageName = nil;
  
        imageName =  [NSString stringWithFormat:@"%d",i + 1];
            
     
        imageView.image = [UIImage imageNamed:imageName];
        
        // 设置frame
        imageView.frame = CGRectMake(i *imageW, 0, imageW, imageH);
       
        [scrollview addSubview:imageView];
    }
    
    scrollview.pagingEnabled = YES;
    scrollview.contentSize = CGSizeMake(newFeatureImageCount * imageW, 0);
    scrollview.showsHorizontalScrollIndicator = NO;
}

/**
 *  创建PageControl
 */
- (void)setUpPageControl
{
    UIPageControl *pageControl = [[UIPageControl alloc]init];
    pageControl.center = CGPointMake(self.view.frame.size.width * 0.5, self.view.frame.size.width  - 30);
   
    // 不需要pageController的显示，隐藏颜色即可，不删除，由于要判断滑动到一定程度，直接进入登录界面
    pageControl.currentPageIndicatorTintColor =  [UIColor clearColor];    //   GTColor(253, 98, 42);
    pageControl.pageIndicatorTintColor = [UIColor clearColor];    // GTColor(189, 189, 189);
    [self.view addSubview:pageControl];
    self.pageControl = pageControl;
}
#pragma mark - UIScrollViewDelegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
//    // 获得页码
//    CGFloat doublePage = scrollView.contentOffset.x  / scrollView.width;
//    int intPage = (int)(doublePage + 0.5);
//    
//    // 设置页码
//    self.pageControl.currentPage = intPage;
    
}


@end
